<template>
	<view>
		<bg-video></bg-video>
		<cu-custom bgColor="bg-gradual-blue" :isBack="false">
			<block class="text-blue" slot="content">避风塘自习室</block>
		</cu-custom>
		<view style="height: 100vh;" class="">
			<view>
				<view v-for="(nr, index) in nrs" :key="index">
					<view>
						<view class="flex justify-start bg-white">
							<view class="bg-red" style="width: 10px; height: 40px;"></view>
							<view style="height: 40px; line-height: 40px; padding-left: 10px;">{{nr.name}}</view>
						</view>
						<view style="background-color: rgba(255, 255, 255, 0.2); padding: 20px;">
							<view class="flex justify-start" style="margin-top: 5px; overflow: hidden; border-radius: 5px; width: 100%;" 
								v-for="(sb, sndex) in nr.subnr" :key="sndex">
								<image style="width: 120px; height: 80px;" mode="scaleToFill" :src="sb.pic"></image>
								<view style="width: calc(100% - 120px); padding: 5px;" class="bg-white flex flex-direction justify-between">
									<view>{{sb.title}}</view>
									<view class="flex justify-end">
										<text @click="toxiangxi(nr, sb)" class="bg-red" style="padding: 5px;">阅读全文</text>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view style="position: fixed; bottom: 0px; width: 100%;" class="padding-lg">
				<button style="width: 100%;" class="cu-btn bg-blue padding-xl text-xl" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">进入自习室</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				to: "author",
				nrs: [
					{
						code: "bdsd",
						name: "必读书单",
						subnr: [
							{
								id: 1,
								title: "大学生经典必读书单来啦！",
								pic: "https://univs-news-1256833609.file.myqcloud.com/zmt/90f077b927d84a3d8d063bf1c4a55259.png"
							},
							{
								id: 2,
								title: "闲暇是人生的精华 | 每周推书",
								pic: "https://univs-news-1256833609.file.myqcloud.com/resource_files/cont_pub/G/AI4SG/H25OA6VTVZEDBGSTPPEASBNJ6U.png"
							},
							{
								id: 3,
								title: "新学期，新气象，开学书单等你查收！",
								pic: "https://univs-news-1256833609.file.myqcloud.com/zmt/4e15b02b3ba84d93b3bdd240ca32d8cc.png"
							},
						]
					},
					{
						code: "dsdr",
						name: "读书达人",
						subnr: [
							{
								id: 1,
								title: "浅谈《瓦尔登湖》经济篇的生活论与生命论",
								pic: "https://univs-news-1256833609.file.myqcloud.com/resource_files/cont_pub/2/AIZ52/NMZJ2FICGZEYTPACISICQSRVCQ.jpg"
							},
							{
								id: 2,
								title: "阅读的意义：我从阅读中获得了什么",
								pic: "https://univs-news-1256833609.file.myqcloud.com/zmt/36aec8734e45494cab06010a5eb56502.png"
							},
							{
								id: 3,
								title: "海丽：书海泛舟，乘风远航——“阅读之星”风采展示",
								pic: "https://univs-news-1256833609.file.myqcloud.com/zmt/4c856d8c14ad4c218b10f076764709a4.png"
							},
						]
					},
					// {
					// 	code: "dkjt",
					// 	name: "大咖讲坛",
					// 	subnr: [
					// 		{
					// 			id: 1,
					// 			title: "孙玉明：《红楼梦》的是与非",
					// 			pic: "https://univs-news-1256833609.file.myqcloud.com/zmt/4af108b9c69343fd9cf2bf3590231647.png"
					// 		},
					// 		{
					// 			id: 2,
					// 			title: "图苑夜话 | 回到1200年前“推敲”贾岛的一生",
					// 			pic: "https://univs-news-1256833609.file.myqcloud.com/zmt/a24fb6dc70b345e8835e9ee88386ee98.png"
					// 		},
					// 		{
					// 			id: 3,
					// 			title: "徐则臣：花街·王城·到世界去——我的写作之旅！",
					// 			pic: "https://univs-news-1256833609.file.myqcloud.com/123/upload/resources/image/8250905.jpg"
					// 		},
					// 	]
					// },
					// {
					// 	code: "xlyz",
					// 	name: "心灵驿站",
					// 	subnr: [
					// 		{
					// 			id: 1,
					// 			title: "拯救期末焦虑，快速找回状态",
					// 			pic: "https://univs-news-1256833609.file.myqcloud.com/zmt/0e5d30539dd444f08c6523a476f9209f.png"
					// 		},
					// 		{
					// 			id: 2,
					// 			title: "丁闽江：2024年，大学生的正确打开方式",
					// 			pic: "https://univs-news-1256833609.file.myqcloud.com/zmt/d6fb99530ebc4f8e89cdbcef7316adc5.jpg"
					// 		},
					// 		{
					// 			id: 3,
					// 			title: "悦读丨世界因不同而精彩 做独一无二的你",
					// 			pic: "https://univs-news-1256833609.file.myqcloud.com/zmt/239657621f15435fba7acbfa405d0b36.png"
					// 		},
					// 	]
					// },
				]
			}
		},
		onLoad: function(option) {
			let accountInfo = uni.getAccountInfoSync();
			let appId = accountInfo.miniProgram.appId;
			this.http.get({
				url: "/store/info",
				param: {
					appId,
				}
			}).then(res => {
				this.common.setAttribute("store", res);
			});
		},
		methods: {
			toxiangxi: function(nr, sb) {
				let code = nr.code;
				let data =  {
					code: nr.code,
					title: sb.title,
					id: sb.id
				};

				uni.navigateTo({
					url: "../pages/haha?item="+ encodeURIComponent(JSON.stringify(data))
					
				});
			},
			getPhoneNumber: function(e) {
				let phoneCode = e.detail.code;
				let accountInfo = uni.getAccountInfoSync();
				let appId = accountInfo.miniProgram.appId;
				uni.login({
					success: res => {
						console.log(res);
						
						this.http.get({
							url: "/client/login/wx-code",
							param: {
								code: res.code,
								appId,
								phoneCode,
							}
						}).then(res => {
							console.log("登陆后")
							console.log(res);
							this.common.setAttribute("store", res.store);
							this.common.setAttribute("autor", res);
							uni.redirectTo({
								url: "../pages/author"
							});
						});
					}
				});
			},
		}
	}
</script>

<style scoped>
</style>
